package com.canteen.create.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.canteen.create.entity.ColumnInformation;
import com.canteen.create.entity.TableInformation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CreateFactoryDao extends BaseMapper<ColumnInformation> {

    @Select("<script>" +
            " select table_name, table_comment from information_schema.tables " +
            " where table_schema = #{databaseName} and table_type = 'BASE TABLE' " +

            "<if test='tableList != null and tableList.size &gt; 0'>" +
                " and table_name in " +
                "<foreach collection=\"tableList\" separator=\",\" item=\"item\" open=\"(\" close=\")\">" +
                    "#{item}" +
                "</foreach>"+
            "</if>" +

            "</script>")
    List<TableInformation> getTableName(@Param("databaseName") String databaseName, @Param("tableList") List<String> tableList);

    @Select("select column_name, data_type, column_comment, column_key, extra from information_schema.columns " +
            " where table_schema = #{databaseName} and table_name = #{tableName}")
    List<ColumnInformation> getColumnName(@Param("databaseName") String databaseName, @Param("tableName") String tableName);

}
